package com.learn.english.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * @author TISNIW
 * @version 1.0
 * @desc
 */
@Getter
@AllArgsConstructor
public enum Category {
    // 基础英语
    BEGINNER(1, "初级英语"),
    INTERMEDIATE(2, "中级英语"),
    ADVANCED(3, "高级英语"),
    GRAMMAR(4, "语法精讲"),
    VOCABULARY(5, "词汇积累"),

    // 考试类英语
    IELTS_PREP(10, "雅思备考"),
    TOEFL_PREP(11, "托福备考"),
    CET4(12, "大学英语四级"),
    CET6(13, "大学英语六级"),
    TOEIC(14, "托业英语"),
    GRE(15, "GRE考试英语"),
    GMAT(16, "GMAT考试英语"),

    // 职场与商务英语
    BUSINESS(20, "商务英语"),
    JOB_INTERVIEW(21, "求职面试英语"),
    OFFICE_ENGLISH(22, "职场办公英语"),
    EMAIL_WRITING(23, "英语邮件写作"),

    // 口语与听力
    CONVERSATION(30, "口语会话"),
    LISTENING(31, "听力训练"),
    PRONUNCIATION(32, "发音纠正"),
    SPOKEN_ENGLISH(33, "实用口语表达"),

    // 专业领域英语
    MEDICAL(40, "医学英语"),
    LEGAL(41, "法律英语"),
    ENGINEERING(42, "工程英语"),
    ACADEMIC(43, "学术英语"),
    TOURISM(44, "旅游英语"),

    // 青少年英语
    KIDS(50, "少儿英语"),
    JUNIOR_HIGH(51, "初中英语"),
    HIGH_SCHOOL(52, "高中英语"),
    COLLEGE(53, "大学英语"),

    // 文化与兴趣类
    MOVIE_ENGLISH(60, "电影英语"),
    SONG_ENGLISH(61, "英文歌曲学习"),
    CULTURE(62, "英美文化介绍"),
    IDIOMS(63, "英语习语与俚语")
            ;

    private final Integer id;
    private final String name;

    // 通过 id 获取对应的枚举项
    public static Optional<Category> fromId(Integer id) {
        return Arrays.stream(values())
                .filter(category -> category.getId().equals(id))
                .findFirst();
    }

    // 通过 name 获取对应的枚举项
    public static Optional<Category> fromName(String name) {
        return Arrays.stream(values())
                .filter(category -> category.getName().equals(name))
                .findFirst();
    }

    // 通过 name 获取 id
    public static Optional<Integer> getIdFromName(String name) {
        return fromName(name).map(Category::getId);
    }

    // 通过 id 获取 name
    public static Optional<String> getNameFromId(Integer id) {
        return fromId(id).map(Category::getName);
    }
}
